package cn.tedu.lucky.draw.server.controller;

import cn.tedu.lucky.draw.server.common.annotation.OperationLog;
import cn.tedu.lucky.draw.server.common.result.JsonResult;
import cn.tedu.lucky.draw.server.protocol.po.Prize;
import cn.tedu.lucky.draw.server.protocol.query.PrizeQuery;
import cn.tedu.lucky.draw.server.service.IPrizeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @RequestBody
 * @ResponseBody
 */
@RestController
@CrossOrigin // 允许跨域请求
public class PrizeController {

    @Autowired
    private IPrizeService prizeService;

    @PostMapping("/draw/prize/findAll")
    public JsonResult<List<Prize>> findAll(@RequestBody PrizeQuery prizeQuery) {

        List<Prize> prizeList = prizeService.findAll(prizeQuery);

        return JsonResult.ok(prizeList);

    }

    @PostMapping("/draw/prize/save")
    @OperationLog(operation = "新增奖品")
    public JsonResult save(@RequestBody Prize prize) {

        prizeService.save(prize);

        return JsonResult.ok();
    }

    @GetMapping("/draw/prize/findPrize/{id}")
    public JsonResult<List<Prize>> findPrizeByActivityId(@PathVariable("id") Long activityId) {
        List<Prize> prizeList=prizeService.findAllByActivityId(activityId);
        return JsonResult.ok(prizeList);
    }

    @GetMapping("/draw/price/noBindPrize/{id}")
    public JsonResult<List<Prize>> findNoBindPrizeByActivityId(@PathVariable("id") Long activityId) {
        List<Prize> prizeList=prizeService.findNoBindPrizeByActivityId(activityId);
        return JsonResult.ok(prizeList);
    }
}